// pages/play/musicPlay/musicPlay.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    audio1:null,
    totalTime:0,
    currentTime:0,
    timer:null,
    
    musicList:[{
       musicId:111,
       musicTitle:"手中的蔷薇",
       musicAuthor:"邓紫棋",
       musicUrl:"/musics/手中的蔷薇.mp3",
       lyText:""
    },{
      musicId:112,
      musicTitle:"手中的蔷薇",
      musicAuthor:"邓紫棋",
      musicUrl:"/musics/手中的蔷薇.mp3",
   },{
    musicId:113,
    musicTitle:"手中的蔷薇",
    musicAuthor:"邓紫棋",
    musicUrl:"/musics/手中的蔷薇.mp3",
 }],
    
    lyObj:[{
         startTime:3,
         lyText:"1"
    },{
      startTime:6,
      lyText:"2"
    },{
      startTime:9,
      lyText:"3"
    },{
      startTime:12,
      lyText:"4"
    },{
      startTime:15,
      lyText:"5"
    },{
      startTime:17,
      lyText:"6"
    },{
      startTime:20,
      lyText:"7"
    },{
      startTime:25,
      lyText:"9"
    },{
      startTime:27,
      lyText:"10"
    },{
      startTime:28,
      lyText:"11"
    },{
      startTime:29,
      lyText:"12"
    },{
      startTime:30,
      lyText:"13"
    },{
      startTime:31,
      lyText:"14"
    },{
      startTime:32,
      lyText:"15"
    },{
      startTime:30,
      lyText:"16"
    },{
      startTime:31,
      lyText:"17"
    }]
  

  },

  playEvent(){
    
    this.data.audio1.play()
    // 定时器
    let timer = setInterval(()=>{
        this.setData({
          currentTime:++this.data.currentTime
        })
    },1000)

    this.setData({
      timer 
    })
    
  },
  

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

    let obj = [{
      "startTime":3,
      "lyText":"1"
 },{
   "startTime":6,
   "lyText":"2"
 },{
   "startTime":9,
   "lyText":"3"
 }]


    const audio1 = wx.createInnerAudioContext()
    this.setData({
      audio1:audio1
    })
    this.data.audio1.src = "/musics/手中的蔷薇.mp3"
    console.log(this.data.audio1);
    //监听 获取总时长
    this.data.audio1.onCanplay(()=>{
      // 获取总时长
      this.data.audio1.duration
      // 异步

        wx.nextTick(()=>{
          console.log(this.data.audio1.duration);
          this.setData({
            totalTime:this.data.audio1.duration
          })
        })
    })
    // this.data.audio1.currentTime = 277
    this.data.audio1.onEnded(()=>{
      console.log("结束");
      // 关闭定时器
      clearInterval(this.data.timer)
      // 回归0状态
      this.setData({
        currentTime:0
      })
    })


    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})